﻿Imports System.Windows.Forms

Public Class Main
    Private WithEvents frmPedidos As Pedidos
    Private m_ChildFormNumber As Integer

    Private Sub StatusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles StatusBarToolStripMenuItem.Click
        Me.StatusStrip.Visible = Me.StatusBarToolStripMenuItem.Checked
    End Sub

    Private Sub ClientesMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClientesMenu.Click
        Dim listForm As New ListaClientes
        Dim toolStripButton1 As ToolStripButton = New System.Windows.Forms.ToolStripButton()

        With toolStripButton1
            .DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
            .TextAlign = System.Drawing.ContentAlignment.MiddleRight
            .Name = listForm.Name
            .Text = "&Clientes"
            .TextAlign = System.Drawing.ContentAlignment.MiddleRight
            '.Checked = True
        End With

        sender.enabled = False
        'closeAllChilds()

        With listForm
            .Text = "Listado Clientes"
            .delStoreProc = "delCliente"
            .countStoreProc = "ClientCount"
            .modifyForm = "Clientes"
            .cliStoreProc = "ListaCortaClientes"
            .MdiParent = Me
            .Show()
        End With
        m_ChildFormNumber += 1
    End Sub

    Private Sub CloseMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseMenu.Click
        Me.Close()
        Me.Dispose()
    End Sub

    Private Sub VendorsMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VendorsMenu.Click
        Dim listForm As New ListaClientes
        Dim toolStripButton1 As ToolStripButton = New System.Windows.Forms.ToolStripButton()

        With toolStripButton1
            .DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
            .TextAlign = System.Drawing.ContentAlignment.MiddleRight
            .Name = "tSRepresentantes"
            .Text = "&Representantes"
            .TextAlign = System.Drawing.ContentAlignment.MiddleRight
            '.Checked = True
        End With

        sender.enabled = False
        'closeAllChilds()
        With listForm
            .Text = "Listado Representantes"
            .delStoreProc = "delRepresentante"
            .countStoreProc = "RepresentantesCount"
            .modifyForm = "Representantes"
            .cliStoreProc = "ListaRepresentantes"
            .DataGridView1.RowsDefaultCellStyle.BackColor = Color.PapayaWhip
            .DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightYellow
            .MdiParent = Me
            .Show()
        End With
        m_ChildFormNumber += 1
    End Sub

    Private Sub closeAllChilds()
        ' Close all child forms of the parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
            ChildForm.Dispose()
        Next
    End Sub

    Private Sub FrabricantesMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FrabricantesMenu.Click
        Dim listForm As New ListaClientes
        sender.enabled = False
        closeAllChilds()
        With listForm
            .Text = "Listado Fabricantes"
            .delStoreProc = "delFabricante"
            .countStoreProc = "FabricantesCount"
            .modifyForm = "Fabricante"
            .cliStoreProc = "ListaFabricantes"
            .DataGridView1.RowsDefaultCellStyle.BackColor = Color.Azure
            .DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Lavender
            .MdiParent = Me
            .Show()
        End With
        m_ChildFormNumber += 1
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        Dim miAbout As New SplashScreen1
        miAbout.ShowDialog()
    End Sub

    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        Control.CheckForIllegalCrossThreadCalls = False
        'Dim Packet As New APing.CPing
        ''Dim retValue
        'Packet.HostName = "neciored.dyndns.org"
        'If Packet.Open Then
        '    'retValue = 
        '    If Packet.Ping <> -1 Then
        '        Me.WebHelp.Url = New System.Uri("http://neciored.dyndns.org/clickonce/Furniture/banner.htm", System.UriKind.Absolute)
        '    Else
        '        Me.WebHelp.Url = New System.Uri(Application.StartupPath + "\banner.htm", System.UriKind.Absolute)
        '    End If
        '    Packet.Close()
        'Else
        '    Me.WebHelp.Url = New System.Uri(Application.StartupPath + "\banner.htm", System.UriKind.Absolute)
        'End If
        'Packet = Nothing
    End Sub

    Private Sub ArticulosMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ArticulosMenu.Click
        Dim frmArticulos As New Articulos
        closeAllChilds()
        With frmArticulos
            .DataGridView1.RowsDefaultCellStyle.BackColor = Color.Azure
            .DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Lavender
            .MdiParent = Me
            .Show()
        End With

    End Sub

    Private Sub ToolStrip_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs)
        For Each f As Form In Me.MdiChildren
            If f.Name = e.ClickedItem.Name Then f.Focus()
        Next
    End Sub

    Public Sub TuMadre()
        'MessageBox.Show("Igotcha")
    End Sub

    Private Sub frmPedidos_ClosePedido(ByVal Numero As Int32) Handles frmPedidos.ClosePedido
        Dim rptVwr As New Listados(Numero)
        frmPedidos.Dispose()
        frmPedidos = Nothing
        With rptVwr
            .MdiParent = Me
            .Show()
        End With
    End Sub

    Private Sub NuevoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NuevoToolStripMenuItem.Click
        frmPedidos = New Pedidos
        With frmPedidos
            .MdiParent = Me
            .Show()
        End With
    End Sub

    Private Sub ListaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListaToolStripMenuItem.Click
        Dim frmListaPedidos = New ListaPedidos
        With frmListaPedidos
            .MdiParent = Me
            .Show()
        End With
    End Sub
End Class
